//
// Created by Jisam on 19/10/2024 19:02.
// Solution of  b
#include <bits/stdc++.h>

#define  int long long
#define  endl "\n"
#define  all(x) (x).begin(),(x).end()
#define  pb push_back
using namespace std;

struct node{
    int a,b,c;
    int ta;
};
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int T,n;
    cin >> T >> n;
    int ans = 0;
    vector<node> arr(n);
    for(int i = 0 ; i < n ; i ++) cin >> arr[i].a;
    for(int i = 0 ; i < n ; i ++) cin >> arr[i].b;
    for(int i = 0 ; i < n ; i ++) cin >> arr[i].c;

    sort(arr.begin(),arr.end(),[&](node n1,node n2){
        return n1.c * n2.b < n2.c * n1.b;
    });
    vector<int> f(100001,-1);
    f[0] = 0;
    for(int i = 0 ; i < n ; i ++){
        for(int j = T;j >= 0; j--){
            if(f[j] != -1 && j + arr[i].c <= T){
                f[j + arr[i].c] = max(f[j + arr[i].c],f[j] + arr[i].a - (j + arr[i].c) * arr[i].b);
            }
        }
    }
    for(int i = 0 ; i <= T ; i ++)
        ans = max(ans,f[i]);
    cout << ans <<endl;
    return 0;
}